package com.zjzaki.thingsboard.util;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class InternetUtil {

    private Activity activity;

    public InternetUtil(Activity activity) {
        this.activity = activity;
    }

    public boolean isInternetConnection(){
        //检查是否连接到互联网
        ConnectivityManager systemService = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
        //得到网络信息
        NetworkInfo activeNetworkInfo = systemService.getActiveNetworkInfo();
        //得到网络是否连接
        boolean isConnected = activeNetworkInfo !=null && activeNetworkInfo.isConnectedOrConnecting();
        //返回结果
        return isConnected;
    }
}
